<?php

/**
 * @Author: king
 * @Date:   2019-01-04 19:36:13
 * @Last Modified by:   king
 * @Last Modified time: 2019-04-04 20:58:10
 */
namespace App\Http\Controllers\Api\v2;
use App\Http\Controllers\Api\BaseController;
use App\Tools\HoroscopeData;
use App\Models\Api\Recode;
use Illuminate\Http\Request;

class HoroscopeController extends BaseController
{
    /**
     * 八字页面
     * @return \think\response\Json
     * @throws \app\common\lib\exception\ApiException
     */
    public function index(Request $request)
    {
        $rid = $request->input('id', 0);
        $time_start = $request->input('time_start', 23);
        $time_type = $request->input('time_type', 0);

        if (!in_array($time_start, [0, 23]))
        {
            $time_start = 0;
        }

        if (!in_array($time_type, [0, 1]))
        {
            $time_start = 0;
        }

        $recode = (new Recode())->getRecode(['id' => $rid, 'uid' => $request->uid]);

        $now = time();

        $advance = [
            'year' => date('Y', $now) * 1,
            'month' => date('m', $now) * 1,
            'day' => date('d', $now) * 1,
            'hour' => date('H', $now) * 1,
            'minute' => date('i', $now) * 1,
            'timezone' => 8,
            'is_summer' => 0,
        ];

        $option = [
            'recode' => $recode,
            'time_start' => $time_start,
            'time_type' => $time_type,
            'advance' => $advance,
        ];

        $data = HoroscopeData::getInstance($option)->getUserData();

        return show(config('code.success'), '', $data);
    }
}
